Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add B2C user docs #140

Merged
merged 3 commits into from
Sep 14, 2023
Merged

doc: add B2C user docs #140

merged 3 commits into from
Sep 14, 2023

Conversation

davidhuser
Copy link
Contributor

@davidhuser davidhuser commented Jul 17, 2023

This PR is related to issue #136 and adds the first draft of B2C documentation, based on the single- and multi-tenant setups, with a few necessary changes.

With these documented changes I can already log in via OpenAPI's "Authorize" button.

But when I GET a secured endpoint:

@router.get('/auth', dependencies=[Security(azure_scheme)])
async def secure_endpoint():
    return {'message': 'Hello, secure world!'}

I get the following HTTP 401 error:

Unable to process jwt token. Uncaught error: 2 validation errors for User
oid
  field required (type=value_error.missing)
tid
  field required (type=value_error.missing)
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/fastapi_azure_auth/auth.py", line 208, in __call__
    user: User = User(
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__

tracing to here: https://github.com/Intility/fastapi-azure-auth/blob/main/fastapi_azure_auth/auth.py#L208

is there a setup step I'm missing? Many thanks!

@JonasKs
Copy link
Member

JonasKs commented Jul 17, 2023

Hi!

Thank you so much!😊 I'm out on vacation right now, so the review probably won't come until next week some time.

Regarding the errors, it's a bug, we haven't been good enough at testing B2C tokens with the new user model.
B2C tokens probably don't have a tid and oid claim.

The fix is to make the tid and oid optional fields.
I wish we could have a better solution for separate models for B2C, but Python typing system is a bit hard to work with when you return a union of multiple models, and require the developer to isintance() check which model it is at all times - a bad developer experience.

CC @omBratteng @enadeau

@omBratteng
Copy link
Contributor

I have never worked with B2C tokens, but I see Microsoft has a list of the claims in a B2C token.

@davidhuser
Copy link
Contributor Author

Thanks for your quick reply 👍

I could reduce the amount of validation errors to only choke on tid by including the User ID as a claim.

But with tid it's trickier without touching the fastapi-azure-auth library. Would it make sense to add a simple PR to make tid optional in the Pydantic model for User?

@JonasKs
Copy link
Member

JonasKs commented Jul 17, 2023

Yes, exactly, a PR would be perfect! Both should be optional 😊

@codecov
Copy link

codecov bot commented Aug 4, 2023

Codecov Report

Merging #140 (2c05d06) into main (f6605a5) will not change coverage.
Report is 5 commits behind head on main.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #140   +/-   ##
=======================================
  Coverage   100.0%   100.0%           
=======================================
  Files           6        6           
  Lines         248      247    -1     
=======================================
- Hits          248      247    -1     

see 1 file with indirect coverage changes

@davidhuser davidhuser changed the title [WIP] doc: add B2C user docs doc: add B2C user docs Aug 4, 2023
@davidhuser
Copy link
Contributor Author

@JonasKs this PR is ready for review. With recent version 4.2.1 I was able to log in as per steps in the new B2C documentation.

@JonasKs
Copy link
Member

JonasKs commented Aug 4, 2023

Thank you for your feedback - happy it works😊 This deserve a proper review where I try it out, so I'll make some time next week to do so.

@davidhuser
Copy link
Contributor Author

hi there, did you find the time to take a look at it? disclaimer, I've been using it successfully during development and deployments but have not yet pushed to real users yet.

@akarray
Copy link

akarray commented Aug 24, 2023

hi there, did you find the time to take a look at it? disclaimer, I've been using it successfully during development and deployments but have not yet pushed to real users yet.

Thanks @davidhuser for this amazing work. I'm excited to see this feature @JonasKs

@JonasKs
Copy link
Member

JonasKs commented Sep 1, 2023

I'm so sorry, I've struggled to find time, but I should have time next week 😊

@akarray
Copy link

akarray commented Sep 12, 2023

I'm so sorry, I've struggled to find time, but I should have time next week 😊

I'm excited to see this feature @JonasKs
How can I help ?

@JonasKs
Copy link
Member

JonasKs commented Sep 12, 2023

I'll look at this today, but please note this isn't a feature, it's documentation. You can still use it, even if it's not merged.

@akarray
Copy link

akarray commented Sep 12, 2023

I'll look at this today, but please note this isn't a feature, it's documentation. You can still use it, even if it's not merged.

Oh sorry I haven't see that claims tid and oid are now optional and merge are done.
Thank you

@JonasKs
Copy link
Member

JonasKs commented Sep 12, 2023

Correct 😊

@JonasKs
Copy link
Member

JonasKs commented Sep 12, 2023

This looks very good, thank you so much for the time and effort 🙏 Sorry for the late review.

I'll merge when you accept / resolve threads. 😊

Co-authored-by: Jonas Krüger Svensson <jonas-ks@hotmail.com>
@davidhuser
Copy link
Contributor Author

threads are resolved / suggestions accepted, so if the checks are not a problem we can merge 🙂

@JonasKs JonasKs merged commit 31076c1 into Intility:main Sep 14, 2023
3 of 4 checks passed
@JonasKs
Copy link
Member

JonasKs commented Sep 14, 2023

Thank you so much 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants